<%@ page import="java.io.PrintWriter" %>
<%@ page import="all.JdbcUtils" %><%--
  Created by IntelliJ IDEA.
  User: 黄坤鹏
  Date: 2021/12/13
  Time: 8:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<%
    String username = request.getParameter("u");
    String password = request.getParameter("p");
    String code = request.getParameter("c");
    HttpSession session1 = request.getSession();
    Object c = session1.getAttribute("C");
    boolean isTrue = c!=null&&code!=null&&code.equals(c);
    if(!isTrue){
        PrintWriter writer = response.getWriter();
        writer.write("code is error");
        writer.flush();
        writer.close();
        return;
    }
    String sql = "SELECT id FROM `user` WHERE username=? AND password=md5(?)";
    Long id = JdbcUtils.select(sql,Long.class,username,password);
    if(id  !=null){
        response.sendRedirect("/hkp/");
    }else{
        response.sendRedirect("hkp/login.jsp");
    }





//    String message = id!=null?"登陆成功!":"登陆失败!";
//    response.setContentType("text/html;charset=utf-8");
//    PrintWriter writer = response.getWriter();
//    writer.write(message);
//    writer.flush();
//    writer.close();

%>
